﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace YArchitech.Controls
{
	public class HYGridView : DataGridView
	{
		public HYGridView()
		{
			this.InitializeComponent();
		}

		public static System.Drawing.Color EditableColor
		{
			get
			{
				return HYGridView.editableColor;
			}
		}

		public void SaveColumnState()
		{
		}

		public void DeleteAllRows()
		{
			for (int i = base.Rows.Count - 1; i > -1; i--)
			{
				base.Rows.RemoveAt(i);
			}
			base.Rows.Clear();
		}

		public void DeleteSelectedRows()
		{
			for (int i = base.SelectedRows.Count - 1; i > -1; i--)
			{
				base.Rows.Remove(base.SelectedRows[i]);
			}
		}

		public bool SelectRow(DataGridViewRow rowToSelect)
		{
			foreach (object obj in base.SelectedRows)
			{
				((DataGridViewRow)obj).Selected = false;
			}
			rowToSelect.Selected = true;
			base.CurrentCell = rowToSelect.Cells[0];
			this.BeginEdit(true);
			if (!rowToSelect.Displayed)
			{
				base.FirstDisplayedScrollingRowIndex = rowToSelect.Index;
			}
			return true;
		}

		public int AddNewRow()
		{
			int num = base.Rows.Add();
			this.SelectRow(num);
			return num;
		}

		public bool SelectRow(int rowIndex)
		{
			return this.SelectRow(base.Rows[rowIndex]);
		}

		public string GetCellText(int row, int col)
		{
			DataGridViewCell cell = this.GetCell(row, col);
			if (cell == null || cell.Value == null)
			{
				return string.Empty;
			}
			return cell.GetText();
		}

		public void SetCellValue(int row, int col, double newValue)
		{
			DataGridViewCell cell = this.GetCell(row, col);
			if (cell == null)
			{
				return;
			}
			cell.SetValue(newValue, 3);
		}

		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			base.AllowUserToAddRows = false;
			base.AllowUserToDeleteRows = false;
			base.AllowUserToResizeRows = false;
			dataGridViewCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle.BackColor = HYGridView.alternatingBackColor;
			base.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			base.BackgroundColor = SystemColors.Window;
			base.ColumnHeadersHeight = 32;
			base.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
			base.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
			base.GridColor = HYGridView.gridColor;
			base.Location = new System.Drawing.Point(0, 0);
			base.Name = "HYGridView";
			base.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			dataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle2.BackColor = HYGridView.backColor;
			base.RowsDefaultCellStyle = dataGridViewCellStyle2;
			base.RowTemplate.Height = 24;
			base.RowHeadersWidth = 32;
			base.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			base.ShowRowErrors = false;
		}

		private static System.Drawing.Color gridColor = System.Drawing.Color.FromArgb(79, 129, 189);

		private static System.Drawing.Color alternatingBackColor = System.Drawing.Color.FromArgb(219, 229, 241);

		private static System.Drawing.Color editableColor = System.Drawing.Color.FromArgb(255, 255, 200);

		private static System.Drawing.Color backColor = System.Drawing.Color.White;
	}
}
